package rs.pnv.model.insurance;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.validator.constraints.NotBlank;

import rs.pnv.model.AbstractEntity;

@Entity
@Table(name = "SEP_TRAVEL_INSURANCE")
@XmlAccessorType(XmlAccessType.FIELD)
public class TravelInsurance extends AbstractEntity {

	public enum Region {
		EUROPE,
		ASIA,
		NORTH_AMERICA,
		SOUTH_AMERICA,
		AFRICA,
		AUSTRALIA
	}

	public enum Age {
		UNDER_18,
		BETWEEN_18_AND_60,
		OVER_60
	}

	public enum InsuranceValue {
		E10K,
		E20,
		E30K,
		E50K,
		E100K
	}

	@NotBlank
	@Column(nullable = false, unique = true)
	@XmlElement(nillable = false)
	private Integer duration;

	@NotBlank
	@Column(nullable = false, unique = true)
	@XmlElement(nillable = false)
	private Region region;

	@NotBlank
	@Column(nullable = false, unique = true)
	@XmlElement(nillable = false)
	private Integer numberOfPersons;

	@NotBlank
	@Column(nullable = false, unique = true)
	@XmlElement(nillable = false)
	private Age age;

	private String sport = null;

	@NotBlank
	@Column(nullable = false, unique = true)
	@XmlElement(nillable = false)
	private InsuranceValue value;

	public TravelInsurance() {

	}

	public Integer getDuration() {
		return duration;
	}

	public void setDuration(Integer duration) {
		this.duration = duration;
	}

	public Region getRegion() {
		return region;
	}

	public void setRegion(Region region) {
		this.region = region;
	}

	public Integer getNumberOfPersons() {
		return numberOfPersons;
	}

	public void setNumberOfPersons(Integer numberOfPersons) {
		this.numberOfPersons = numberOfPersons;
	}

	public Age getAge() {
		return age;
	}

	public void setAge(Age age) {
		this.age = age;
	}

	public String getSport() {
		return sport;
	}

	public void setSport(String sport) {
		this.sport = sport;
	}

	public InsuranceValue getValue() {
		return value;
	}

	public void setValue(InsuranceValue value) {
		this.value = value;
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder()
				.append(duration)
				.append(region)
				.append(numberOfPersons)
				.append(age)
				.append(sport)
				.append(value)
				.appendSuper(super.hashCode())
				.hashCode();
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (obj == this) {
			return true;
		}
		if (obj.getClass() != getClass()) {
			return false;
		}

		final TravelInsurance otherTravelInsurance = (TravelInsurance) obj;

		return new EqualsBuilder()
				.append(duration, otherTravelInsurance.getDuration())
				.append(region, otherTravelInsurance.getRegion())
				.append(numberOfPersons, otherTravelInsurance.getNumberOfPersons())
				.append(age, otherTravelInsurance.getAge())
				.append(sport, otherTravelInsurance.getSport())
				.append(value, otherTravelInsurance.getValue())
				.appendSuper(super.equals(obj))
				.isEquals();
	}

	@Override
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
				.append("duration", duration)
				.append("region", region)
				.append("numberOfPersons", numberOfPersons)
				.append("age", age)
				.append("sport", sport)
				.append("value", value)
				.append(super.toString())
				.toString();
	}

}
